package zkk.com.mengqu.fragment;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import zkk.com.mengqu.R;
import zkk.com.mengqu.adapter.CircleFriendSubscribeAdapter;
import zkk.com.mengqu.view.refresh.LoadMoreListView;

/**
 * 饭友圈订阅界面
 */
public class CircleFriendSubscribeFragment extends Fragment{

    private View view;
    private LoadMoreListView listView;
    private SwipeRefreshLayout swipeRefreshLayout;
    private CircleFriendSubscribeAdapter adapter;
    private Context context;
    private boolean isLoad = false;
    private boolean hasMore = true;
    private  String lastId; //最后一个ID
    private  String lastTime;//最后一个的时间

    public static CircleFriendFragment newInstance(){
        CircleFriendFragment gameInfoFragment=new CircleFriendFragment();
        return gameInfoFragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view=inflater.inflate(R.layout.fragment_circle_friend,container,false);
        context=getActivity();
        return view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    private void getAppIndexMore(String dataType,String pageNo3){
        isLoad =false;
        //http://api.moeju.cn//painting/originalList?lastId=&lastTime=0&dk=5ed40069e20354be&ak=~68EECA63-0FB4-1EB8-628D-CDCF663CEB41&v=2.1.0&os=a&channel=Xiaomi
//        APIManager.getInstance().getoriginalList(dataType,pageNo3,"5ed40069e20354be","~68EECA63-0FB4-1EB8-628D-CDCF663CEB41","2.1.0","a","Xiaomi")
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(observer2);
    }



    private  void  init(){
        listView=(LoadMoreListView)view.findViewById(R.id.lv_gameinfo);
        swipeRefreshLayout=(SwipeRefreshLayout)view.findViewById(R.id.sf_gameinfo_swipe_refresh);
        adapter =new CircleFriendSubscribeAdapter(context);
        listView.setAdapter(adapter);

        swipeRefreshLayout.setColorSchemeColors(Color.GREEN, Color.RED, Color.YELLOW);
        swipeRefreshLayout.setEnabled(true);


        listView.setOnLastItemVisibleListener(new LoadMoreListView.OnLastItemVisibleListener() {
            @Override
            public void onLastItemVisible() {

                if (isLoad || !hasMore) {
                    listView.setFooter(LoadMoreListView.Mode.NOMORE);
                    return;
                }
                isLoad = true;
                getAppIndexMore(lastId,lastTime);
                listView.setFooter(LoadMoreListView.Mode.LOAD);
            }
        });
    }
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        init();
    }
}
